﻿Imports System.Windows.Forms

Public Class dlgOutputSet

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        Dim strMsg As String = ""

        'update HLT output settings
        strMsg = "SET_OSET+0+"
        If rbHLTpid.Checked Then
            strMsg &= "1+"
        Else
            strMsg &= "0+"
        End If
        If IsNumeric(tbHLTc.Text) Then
            strMsg &= tbHLTc.Text & "+"
        Else
            MsgBox("Cannot update as HLT cycle is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbHLTp.Text) Then
            strMsg &= tbHLTp.Text & "+"
        Else
            MsgBox("Cannot update as HLT P gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbHLTi.Text) Then
            strMsg &= tbHLTi.Text & "+"
        Else
            MsgBox("Cannot update as HLT I gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbHLTd.Text) Then
            strMsg &= tbHLTd.Text & "+"
        Else
            MsgBox("Cannot update as HLT D gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbHLTh.Text) Then
            strMsg &= tbHLTh.Text & "-"
        Else
            MsgBox("Cannot update as HLT hysteresis is not a valid value.")
            Exit Sub
        End If

        AddToTXstack(strMsg)

        'update MT output settings
        strMsg = "SET_OSET+1+"
        If rbMTpid.Checked Then
            strMsg &= "1+"
        Else
            strMsg &= "0+"
        End If
        If IsNumeric(tbMTc.Text) Then
            strMsg &= tbMTc.Text & "+"
        Else
            MsgBox("Cannot update as MT cycle is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbMTp.Text) Then
            strMsg &= tbMTp.Text & "+"
        Else
            MsgBox("Cannot update as MT P gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbMTi.Text) Then
            strMsg &= tbMTi.Text & "+"
        Else
            MsgBox("Cannot update as MT I gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbMTd.Text) Then
            strMsg &= tbMTd.Text & "+"
        Else
            MsgBox("Cannot update as MT D gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbMTh.Text) Then
            strMsg &= tbMTh.Text & "-"
        Else
            MsgBox("Cannot update as MT hysteresis is not a valid value.")
            Exit Sub
        End If

        AddToTXstack(strMsg)

        'update KET output settings
        strMsg = "SET_OSET+2+"
        If rbKETpid.Checked Then
            strMsg &= "1+"
        Else
            strMsg &= "0+"
        End If
        If IsNumeric(tbKc.Text) Then
            strMsg &= tbKc.Text & "+"
        Else
            MsgBox("Cannot update as KET cycle is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbKp.Text) Then
            strMsg &= tbKp.Text & "+"
        Else
            MsgBox("Cannot update as KET P gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbKi.Text) Then
            strMsg &= tbKi.Text & "+"
        Else
            MsgBox("Cannot update as KET I gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbKd.Text) Then
            strMsg &= tbKd.Text & "+"
        Else
            MsgBox("Cannot update as KET D gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbKh.Text) Then
            strMsg &= tbKh.Text & "-"
        Else
            MsgBox("Cannot update as KET hysteresis is not a valid value.")
            Exit Sub
        End If

        AddToTXstack(strMsg)

        'update STEAM output settings
        strMsg = "SET_OSET+3+"
        If rbSpid.Checked Then
            strMsg &= "1+"
        Else
            strMsg &= "0+"
        End If
        If IsNumeric(tbSc.Text) Then
            strMsg &= tbSc.Text & "+"
        Else
            MsgBox("Cannot update as STEAM cycle is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbSp.Text) Then
            strMsg &= tbSp.Text & "+"
        Else
            MsgBox("Cannot update as STEAM P gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbSi.Text) Then
            strMsg &= tbSi.Text & "+"
        Else
            MsgBox("Cannot update as STEAM I gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbSd.Text) Then
            strMsg &= tbSd.Text & "+"
        Else
            MsgBox("Cannot update as STEAM D gain is not a valid value.")
            Exit Sub
        End If
        If IsNumeric(tbSh.Text) Then
            strMsg &= tbSh.Text & "-"
        Else
            MsgBox("Cannot update as STEAM hysteresis is not a valid value.")
            Exit Sub
        End If

        AddToTXstack(strMsg)


    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub dlgOutputSet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If DisplayInfo(DI_HLT_OP_MODE) = "0" Then
            rbHLTsw.Checked = True
        Else
            rbHLTpid.Checked = True
        End If
        tbHLTc.Text = DisplayInfo(DI_HLT_OP_CYCLE)
        tbHLTp.Text = DisplayInfo(DI_HLT_OP_P)
        tbHLTi.Text = DisplayInfo(DI_HLT_OP_I)
        tbHLTd.Text = DisplayInfo(DI_HLT_OP_D)
        tbHLTh.Text = DisplayInfo(DI_HLT_OP_HYST)

        If DisplayInfo(DI_MASH_OP_MODE) = "0" Then
            rbMTsw.Checked = True
        Else
            rbMTpid.Checked = True
        End If
        tbMTc.Text = DisplayInfo(DI_MASH_OP_CYCLE)
        tbMTp.Text = DisplayInfo(DI_MASH_OP_P)
        tbMTi.Text = DisplayInfo(DI_MASH_OP_I)
        tbMTd.Text = DisplayInfo(DI_MASH_OP_D)
        tbMTh.Text = DisplayInfo(DI_MASH_OP_HYST)

        If DisplayInfo(DI_KETTLE_OP_MODE) = "0" Then
            rbKsw.Checked = True
        Else
            rbKETpid.Checked = True
        End If
        tbKc.Text = DisplayInfo(DI_KETTLE_OP_CYCLE)
        tbKp.Text = DisplayInfo(DI_KETTLE_OP_P)
        tbKi.Text = DisplayInfo(DI_KETTLE_OP_I)
        tbKd.Text = DisplayInfo(DI_KETTLE_OP_D)
        tbKh.Text = DisplayInfo(DI_KETTLE_OP_HYST)

        If DisplayInfo(DI_STEAM_OP_MODE) = "0" Then
            rbSsw.Checked = True
        Else
            rbSpid.Checked = True
        End If
        tbSc.Text = DisplayInfo(DI_STEAM_OP_CYCLE)
        tbSp.Text = DisplayInfo(DI_STEAM_OP_P)
        tbSi.Text = DisplayInfo(DI_STEAM_OP_I)
        tbSd.Text = DisplayInfo(DI_STEAM_OP_D)
        tbSh.Text = DisplayInfo(DI_STEAM_OP_HYST)

    End Sub

    Private Sub rbHLTpid_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbHLTpid.CheckedChanged
        If sender.Checked Then
            tbHLTc.Enabled = True
            tbHLTd.Enabled = True
            tbHLTh.Enabled = True
            tbHLTi.Enabled = True
            tbHLTp.Enabled = True
        Else
            tbHLTc.Enabled = False
            tbHLTd.Enabled = False
            tbHLTh.Enabled = False
            tbHLTi.Enabled = False
            tbHLTp.Enabled = False
        End If
    End Sub

    Private Sub rbMTpid_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbMTpid.CheckedChanged
        If sender.Checked Then
            tbMTc.Enabled = True
            tbMTd.Enabled = True
            tbMTh.Enabled = True
            tbMTi.Enabled = True
            tbMTp.Enabled = True
        Else
            tbMTc.Enabled = False
            tbMTd.Enabled = False
            tbMTh.Enabled = False
            tbMTi.Enabled = False
            tbMTp.Enabled = False
        End If


    End Sub

    Private Sub rbKETpid_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbKETpid.CheckedChanged
        If sender.Checked Then
            tbKc.Enabled = True
            tbKd.Enabled = True
            tbKh.Enabled = True
            tbKi.Enabled = True
            tbKp.Enabled = True
        Else
            tbKc.Enabled = False
            tbKd.Enabled = False
            tbKh.Enabled = False
            tbKi.Enabled = False
            tbKp.Enabled = False
        End If


    End Sub

    Private Sub rbSpid_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbSpid.CheckedChanged
        If sender.Checked Then
            tbSc.Enabled = True
            tbSd.Enabled = True
            tbSh.Enabled = True
            tbSi.Enabled = True
            tbSp.Enabled = True
        Else
            tbSc.Enabled = False
            tbSd.Enabled = False
            tbSh.Enabled = False
            tbSi.Enabled = False
            tbSp.Enabled = False
        End If


    End Sub
End Class
